<?php
/* cut out excessive widht or height,
 * e.g. src 160x120
 *   bounding 100x100
 *   resulting image cut out top 20px, cut out buttom 20px
 *   shrink image to 100x100
 */
#require_once('Imaging.php');
class Imaging_ResizeMode2 extends Imaging {

  function resize($max_w, $max_h){
    // Resize
    $src_w = $this->get_width();
    $src_h = $this->get_height();
    
    if($src_w > $max_w || $src_h > $max_h){
      $a = $max_w / $max_h;
      $b = $src_w / $src_h;
      if ( $a < $b ){ // source is 'wider' ( in term of w/h ratio)
        list($resize_w, $resize_h) = $this->resize_to_height($max_h);
        $this->crop(($resize_w - $max_w)/2, 0, $max_w, $max_h);
       
      } else {
        list($resize_w, $resize_h) = $this->resize_to_width($max_w);
        $this->crop(0, ($resize_h - $max_h)/2, $max_w, $max_h);
       
      }
      $this->resized = FALSE;
      return $this->get_dimension();
    } 
    
    
    $this->resized = FALSE;
    return $this->get_dimension();
  } // end function resize
}
?>